﻿
/*
XSLT Syntax rule for SupertreeTextEditor

Author: Feng Weiguo ( 冯卫国 )
Mail: forxm@21cn.com
Web: www.supertree.org
2008-1

All Rights Reserved, 2008-9

LICENSE: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.
*/

$esoe.$preload(
	"org.supertree.editor.RuleXslt",
	function()
	{
		throw "can not instantiate RuleXslt";;
	},
	function()
	{
		var RC= $esoe.$declare("org.supertree.editor.RuleCompiler");
		this.Compile= RC.Compile;
		
		this._rule=
		{
			sXsltElement: "apply-imports|apply-templates|attribute-set|attribute|call-template|choose|comment|copy-of|copy|decimal-format|element|fallback|for-each|if|import|include|key|message|namespace-alias|number|otherwise|output|param|preserve-space|processing-instruction|sort|strip-space|stylesheet|template|text|transform|value-of|variable|when|with-param",
			sXsltAttr: "language|implements-prefix|xmlns\\:\\w+|case-order|cdata-section-elements|count|data-type|decimal-separator|digit|disable-output-escaping|doctype-public|doctype-system|elements|encoding|exclude-result-prefixes|extension-element-prefixes|format|from|grouping-separator|grouping-size|href|id|indent|infinity|lang|letter-value|level|match|media-type|method|minus-sign|mode|name|NaN|namespace|omit-xml-declaration|order|pattern-separator|percent|per-mille|priority|reuslt-prefix|select|standalone|stylesheet-prefix|terminate|test|use|use-attribute-sets|value|version|zero-digit",
			sXsltKey: "boolean|ceiling|contact|contains|count|current|document|element-available|false|floor|format-number|function-available|generate-id|id|key|lang|last|local-name|name|namespace-uri|normalize-space|not|number|position|round|starts-with|string|string-length|substring|substring-after|substring-before|sum|system-property|translate|true|unparsed-entity-uri",

			sHtmlElement: RC.ToIgnoreCase("a|acronym|address|applet|area|b|base|baseFont|bdo|bgSound|big|blockQuote|body|br|button|caption|center|cite|code|col|colGroup|COMMENT|dd|del|dfn|dir|div|dl|dt|em|embed|fieldSet|font|form|frame|frameSet|head|hn|hr|html|i|iframe|img|IMPORT|input|ins|isIndex|kbd|label|legend|li|link|listing|map|marquee|menu|meta|noBR|noFrames|noScript|object|ol|optGroup|option|p|param|plainText|pre|q|rt|ruby|s|samp|script|select|small|span|strike|strong|style|sub|sup|table|tBody|td|textArea|tFoot|th|tHead|title|tr|tt|u|ul|var|wbr|xml|xmp"),
			sHtmlAttr: RC.ToIgnoreCase("ACCESSKEY|ACTION|ADCREATED|ADVERTISEMENTFILE|ALIGN|ALINK|ALLOWCUSTOMPAGING|ALLOWPAGING|ALLOWSORTING|ALT|ALTERNATETEXT|ALTERNATINGITEMSTYLE|ALTERNATINGITEMTEMPLATE|APPLYSTYLE|ATTRIBUTES|AUTOGENERATECOLUMNS|AUTOPOSTBACK|BACKCOLOR|BACKGROUND|BACKIMAGEURL|BEHAVIOR|BGCOLOR|BGPROPERTIES|BORDER|BORDERCOLOR|BORDERCOLORDARK|BORDERCOLORLIGHT|BORDERSTYLE|BORDERWIDTH|CANCELCOMMAND|CAUSESVALIDATION|CELLPADDING|CELLSPACING|CHARSET|CHECKCHANGED|CHECKED|CLASS|CLASSID|CLEAR|CLICK|CODEBASE|COLOR|COLS|COLSPAN|COLUMNS|COLUMNSPAN|COMMAND|COMMANDARGUMENT|COMMANDNAME|COMMANDARGUMENT|COMMANDNAME|CONTENT|CONTROLS|CONTROLTOCOMPARE|CONTROLTOVALIDATE|COORDS|COPYFROM|CSSCLASS|DATA|DATAFIELD|DATAFORMATSTRING|DATAKEYFIELD|DATAMEMBER|DATANAVIGATEURLFIELD|DATANAVIGATEURLFORMATSTRING|DATASOURCE|DATATEXTFIELD|DATAVALUEFIELD|DAYHEADERSTYLE|DAYNAMEFORMAT|DAYRENDER|DAYSTYLE|DECLARE|DEFER|DELETECOMMAND|DIR|DIRECTION|DOCUMENT|DOCUMENTCONTENT|DOCUMENTSOURCE|DYNSRC|EDITCOMMAND|EDITITEMSTYLE|EDITITEMTEMPLATE|ENABLED|ENABLEVIEWSTATE|ENCTYPE|EXTRACTTEMPLATEROWS|FACE|FIRSTDAYOFWEEK|FONT|FONT-BOLD|FONT-ITALIC|FONT-NAME|FONT-NAMES|FONT-OVERLINE|FONT-SIZE|FONT-STRIKEOUT|FONT-UNDERLINE|FOOTERSTYLE|FOOTERTEMPLATE|FOOTERTEXT|FORECOLOR|FRAMEBORDER|FRAMESPACING|GRIDLINES|GROUPNAME|HEADERSTYLE|HEADERTEMPLATE|HEADERTEXT|HEIGHT|HORIZONTALALIGN|HREF|HSPACE|HTTP-EQUIV|ID|IMAGEALIGN|IMAGEURL|IMPRESSIONS|INNERHTML|INNERTEXT|ISMAP|ITEMCOMMAND|ITEMCREATED|ITEMDATABOUND|ITEMSTYLE|ITEMTEMPLATE|KEYWORD|KEYWORDFILTER|LANGUAGE|LEFTMARGIN|LINK|LOOP|MARGINHEIGHT|MARGINWIDTH|MARKINGHEIGHT|MAXIMUMVALUE|MAXLENGTH|MEDIA|MERGESTYLE|MERGEWITH|METHOD|MINIMUMVALUE|MODE|MULTIPLE|NAME|NAVIGATEURL|NEXTMONTHTEXT|NEXTPAGETEXT|NEXTPREVFORMAT|NEXTPREVSTYLE|NOHREF|NOSHADE|NOWRAP|ONADCREATED|ONBLUR|ONCANCELCOMMAND|ONCHECKEDCHANGED|ONCLICK|ONCOMMAND|ONDAYRENDER|ONDBLCLICK|ONDELETECOMMAND|ONEDITCOMMAND|ONFOCUS|ONITEMCOMMAND|ONITEMCREATED|ONKEYDOWN|ONKEYPRESS|ONKEYUP|ONLOAD|ONMOUSEDOWN|ONMOUSEOUT|ONMOUSEOVER|ONMOUSEUP|ONPAGEINDEXCHANGED|ONSELECTEDINDEXCHANGED|ONSELECTIONCHANGED|ONSERVERCHANGE|ONSERVERCLICK|ONSERVERVALIDATE|ONSORTCOMMAND|ONTEXTCHANGED|ONUNLOAD|ONUPDATECOMMAND|ONVISIBLEMONTHCHANGED|OPTIONAL|OTHERMONTHDAYSTYLE|PAGEINDEXCHANGED|PAGERSTYLE|PAGESIZE|PALETTE|POSTEDFILE|PREVMONTHTEXT|PREVPAGETEXT|PROMPT|READONLY|REL|REPEATCOLUMNS|REPEATDIRECTION|REPEATLAYOUT|REV|ROWS|ROWSPAN|RULES|RUNAT|SCEME|SCROLLAMOUNT|SCROLLDELAY|SCROLLING|SELECTED|SELECTEDDATE|SELECTEDDATES|SELECTEDDAYSTYLE|SELECTEDINDEX|SELECTEDINDEXCHANGED|SELECTEDITEMSTYLE|SELECTEDITEMTEMPLATE|SELECTIONMODE|SELECTMONTHTEXT|SELECTORSTYLE|SELECTWEEKTEXT|SEPARATORSTYLE|SEPARATORTEMPLATE|SERVERCHANGE|SERVERVALIDATE|SHAPE|SHAPES|SHOWDAYHEADER|SHOWFOOTER|SHOWGRIDLINES|SHOWHEADER|SHOWNEXTPREVMONTH|SHOWTITLE|SIZE|SORTEXPRESSION|SPAN|SRC|STANDBY|START|STYLE|TABINDEX|TARGET|TEXT|TEXTALIGN|TEXTCHANGED|TEXTMODE|TITLEFORMAT|TITLESTYLE|TODAYSDATE|TODAYDAYSTYLE|TOOLTIP|TOPMARGIN|TOOLTIP|TOPMARGIN|TRANSFORM|TRANSFORMSOURCE|TYPE|URL|USEMAP|VALIDATE|VALIDATIONEXPRESSION|VALIGN|VALUE|VALUETYPE|VERTICALALIGN|VISIBLEDATE|VISIBLEMONTHCHANGED|VLINK|VSPACE|WEEKENDDAYSTYLE|WIDTH|WRAP"),

			ruleHtmlAttrValue:
				[
					"(\\s+)|(=)|([^\\s=])|($)",
					["","",0],		// spaces
					["","",1,"",	// =
						[
							"(\\s+)|(')|(\")|([^\\s'\"])|($)",
							["","",0],	// spaces
							["Fuchsia","",1,"",	// '
								[
									"(')|($)",
									["Fuchsia","Fuchsia",-3],	// string finish
									["","Fuchsia",0]		// next line, xml attr
								]
							],
							["Fuchsia","",1,"",		// "
								[
									"(\")|($)",
									["Fuchsia","Fuchsia",-3],	// string finish
									["","Fuchsia",0]		// next line, xml attr
								]
							],
							["void","err",-2],	// bad char
							["","",0]	// next line
						]
					],
					["void","err",-1],	// bad char
					["err","err",0]		// next line
				],

			RuleHtmlAttr: function( colorTagEnd )
				{
					var a= new Array(
						"(\\/>)|(>)|(\\s+|=)|((?:"+this.sHtmlAttr+")\\b)|(\\b[a-zA-Z0-9-]+\\b)|(<\\/)|(<)|($)",
						["","",-2],		// tag end />
						["","",1,"","this.rule"],		// tag end >
						["","",0],		// spaces and '='
						["Green","err",1,"","this._rule.ruleHtmlAttrValue"],		// tag attribute
						["alert","err",1,"","this._rule.ruleHtmlAttrValue"],		// unknown tag attribute
						["","err",1,"$P",		// </, must be pop back to this ri
							[
								"(>)|(<)|($)",
								["err","err",-3],	// un-matched >
								["void","errx",-3],	// bad <
								["err","err",0],	// next line
								[colorTagEnd,"err",1,"",	// matched param: tag
									[
										"(>)|($)",
										["","err",-4],
										["","err",0]
									]
								]
							]
						],
						["void","errx",-2],	// bad <
						["","",0]		// next line
					);
					return a;
				}
		}

		this.rule=
		[
			"(<!--)|(<!\\[CDATA\\[)|(<\\?)|(<\\/)|(<)|($)",
			["Green","",1,"",	// <!--
				[
					"(-->)|($)",
					["Green","Green",-1],		// -->
					["Green","Green",0]		// next line
				]
			],
			["Brown","",1,"",	// <![CDATA[
				[
					"(\\]\\]>)|($)",
					["Brown","Brown",-1],	// ]]>
					["","Brown",0]			// next line
				]
			],
			["Blue","",1,"",	// <?
				[
					"(\\?>)|(\\b(?:version|encoding)\\b)|($)",
					["Blue","Blue",-1],	// ]]>
					["Brown","Blue",0],	// for <?xml... key word
					["","Blue",0]			// next line
				]
			],
			["void","",-1],	//	</, pop back
			["","",1,"",		// <
				[
					"(xsl:(?:"+this._rule.sXsltElement+")\\b|msxsl:script\\b)|(xsl:[a-zA-Z-]*)|((?:"+this._rule.sHtmlElement+")\\b)|([a-zA-Z][a-zA-Z0-9]*)|($)",
					["BlueB","err",1,"$1",	// xsl:elements
						[
							"(\\/>)|(>)|(\\s+)|(=)|(\\b(?:"+this._rule.sXsltAttr+")\\b)|(\\b[a-zA-Z-]+\\b)|(<\\/)|(<)|($)",
							["","",-2],		// />
							["","err",1,"","this.rule"],	// >
							["","",0],		// spaces
							["err","err",0],		// '=', no need
							["Brown","err",1,"",	// xsl attributes
								[
									"(\\s+)|(=)|([^\\s=])|($)",
									["","",0],		// spaces
									["","",1,"",	// =
										[
											"(\\s+)|(')|(\")|([^\\s'\"])|($)",
											["","",0],	// spaces
											["Fuchsia","",1,"",	// '
												[
													"(')|(\\b(?:"+this._rule.sXsltKey+")\\b)|($)",
													["Fuchsia","Fuchsia",-3],	// string finish
													["FuchsiaB","Fuchsia",0],	// xsl key
													["","Fuchsia",0]		// next line, xml attr
												]
											],
											["Fuchsia","",1,"",		// "
												[
													"(\")|(\\b(?:"+this._rule.sXsltKey+")\\b)|($)",
													["Fuchsia","Fuchsia",-3],	// string finish
													["FuchsiaB","Fuchsia",0],	// xsl key
													["","Fuchsia",0]		// next line, xml attr
												]
											],
											//["void","err",-2],	// bad char
											["err","err",-2],	// bad char
											["","",0]	// next line
										]
									],
									//["void","err",-1],	// bad char
									["err","err",-1],	// bad char
									["err","err",0]		// next line
								]
							],
							["err","err",0],	// bad xsl attributes
							["","err",1,"$P",		// </, must be pop back to this ri
								[
									"(>)|(<)|($)",
									["err","err",-3],	// un-matched >
									["void","errx",-3],	// bad <
									["err","err",0],	// next line
									["BlueB","err",1,"",	// matched param: xsl:...
										[
											"(>)|($)",
											["","err",-4],
											["","err",0]
										]
									]
								]
							],
							["void","errx",-2],	// bad <
							["","",0]		// next line
						]
					],
					["err","err",-1],	// bad xsl:...
					["Blue","err",1,"$1", this._rule.RuleHtmlAttr('Blue')],	// html tag
					["alert","err",1,"$1", this._rule.RuleHtmlAttr('alert')],	// unknown html tag
					["err","",0]	// next line
				]
			],
			["","",0]	// next line
		];
		
		this.rule.sEndStack="|0|";
		
		this.Compile(this.rule);
		
		this.sName= "Xslt";

		this.aInsert=[
			"Insert &lt;xsl:choose&gt;","\n<xsl:choose>\n    <xsl:when test=\"\"></xsl:when>\n    <xsl:otherwise></xsl:otherwise>\n</xsl:choose>",
			"Insert &lt;xsl:template&gt;","\n<xsl:template match=\"\" mode=\"\">\n</xsl:template>",
			"Insert &lt;xsl:apply-templates&gt;","\n<xsl:apply-templates select=\"\" mode=\"\">\n    <xsl:with-param name=\"\" select=\"\"></xsl:with-param>\n</xsl:apply-templates>",
			"Insert &lt;xsl:variable&gt;","\n<xsl:variable name=\"\" select=\"\"></xsl:variable>"
			];
	}
	);
